#include "mypushbutton.h"
#include<QDebug>
#include<QPropertyAnimation>//特效需要的头文件
mypushbutton::mypushbutton(QString normalimg,QString pressimg)
{this->normalimgpath=normalimg;
    this->pressimgpath=pressimg;
    QPixmap pix;
    bool ret=pix.load(normalimg);
    if(!ret)
    {qDebug()<<"图片加载失败";
        return;
    }
    this->setFixedSize(pix.width()*0.5,pix.height()*0.5);
    this->setStyleSheet("QPushbutton(border:0px)");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width()*0.5,pix.height()*0.5));
    // 设置按钮的背景为透明
    this->setStyleSheet("QPushButton { background: transparent; border: none; }");

    // 设置按钮的掩码，使按钮形状与图片一致
    QPixmap maskPix = pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    this->setMask(maskPix.mask());
   // connect(this,&QPushButton::clicked,this,&::mypushbutton::customClicked);

}
void mypushbutton::zoom1(){
    QPropertyAnimation*animation=new QPropertyAnimation(this,"geometry");
    animation->setDuration(200);
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start();
}
void mypushbutton::zoom2(){    QPropertyAnimation*animation=new QPropertyAnimation(this,"geometry");
    animation->setDuration(200);
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start();

}
